package com.ruoyi.oss.config;

import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.oss.entity.OssEnum;
import com.ruoyi.oss.factory.AbstractOssFactory;
import com.ruoyi.oss.factory.MinioOssFactory;
import com.ruoyi.oss.template.OssTemplate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OssConfig {

    @Value("${oss.type}")
    private String type;

    @Value("${oss.minio.endpoint}")
    private String endpoint;

    @Value("${oss.minio.accessKey}")
    private String accessKey;

    @Value("${oss.minio.secretKey}")
    private String secretKey;

    @Bean
    public OssTemplate getOssTemplate() {
        if (OssEnum.MINIO.getType().equals(this.type)) {
            AbstractOssFactory ossFactory = new MinioOssFactory(this.endpoint, this.accessKey, this.secretKey);
            return ossFactory.createClient();
        } else {
            throw new ServiceException("OSS配置有误！！") ;
        }
    }

}